/*
 * La AI, una stateless machine por ahora...
 *
 * This is part of the game The Rooms
 * Copyright (C) 2010  Elvio Sarquis
 *
 * Get the GNU GPL v3 in http://www.gnu.org/licenses/
 */

package rooms;

import utils.Point;
import utils.Logic;
/**
 *
 * @author dask
 */
public class AI {

    private static Character[] chars;
    private static int[][] lmap;
    private static Point to;

    public static void setAI(Character[] charslist, Map map){

        chars = charslist;
        lmap = map.getBumpMap();
    }

    public static void cls(){
        chars = null;
        lmap = null;
        to = null;
    }

    public static int getAction(int charid){

        boolean los = true;

        Point[] sight = Logic.getRay(chars[charid].getX(),chars[charid].getY(),chars[0].getX(),chars[0].getY(), 5);

        if (sight.length<=2)
            return 2;

        for(Point a:sight){
            if(lmap[a.x()][a.y()]>0 && lmap[a.x()][a.y()]<10)
                los = false;
        }
        
        if(sight[sight.length-1].x()==chars[0].getX() && sight[sight.length-1].y()==chars[0].getY() && los){

            to = sight[1];
            return 1;
        }

        return 0;
    }

    public static Point getTo(){
        
        return to;
    }
}
